package com.fz.wms.adapter;


import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.Toast;

import androidx.recyclerview.widget.RecyclerView;

import com.fz.wms.R;
import com.fz.wms.util.AppInfo;

import java.util.List;

public class MyAdapter extends RecyclerView.Adapter<MyAdapter.MyViewHolder> {

	
	static String s[]={
		"com.tencent.mobileqq",
		"com.xingin.xhs",
		"com.ss.android.ugc.aweme",
		"tv.danmaku.bili"
	};
    private List icon_list;
	private Context context;
    public MyAdapter(Context context,List<AppInfo> icon_list) {
        this.context=context;
		this.icon_list = icon_list;
    }


    @Override
    public MyViewHolder onCreateViewHolder( ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_layout, parent, false);
        return new MyViewHolder(view);
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, int position) {
        
        holder.ImageViewItem.setImageResource((Integer) icon_list.get(position));
		
		
    }

    @Override
    public int getItemCount() {
        return icon_list.size();
    }

    public static class MyViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
        ImageView ImageViewItem;
       
        public MyViewHolder(View itemView) {
            super(itemView);
            ImageViewItem= itemView.findViewById(R.id.imageview);
			itemView.setOnClickListener(this);
			
        }
		
		@Override
		public void onClick(View view) {
			// 处理点击事件
			int position = getAdapterPosition();
			// 在这里执行您希望在项目被点击时执行的操作
				apks(view.getContext(),s[position]);
			    
		}
		public void apks(Context context,String packageName)
		{
		
			
			
		try {
			Intent intent = context.getPackageManager().getLaunchIntentForPackage(packageName);
			if (intent != null) {
				intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
				context.startActivity(intent);
			} else {
				// 应用程序未安装
				Toast.makeText(context, "应用程序未安装", Toast.LENGTH_SHORT).show();
			}
		} catch (ActivityNotFoundException e) {
			// 找不到指定的应用程序
			Toast.makeText(context, "找不到指定的应用程序", Toast.LENGTH_SHORT).show();
		}
		}
		
		
    }
}

